package com.itcpay.jdk8;

import java.util.Comparator;
import java.util.function.BinaryOperator;

public class BinaryOperatorTest {

    public static void main(String[] args) {
        BinaryOperatorTest bot = new BinaryOperatorTest();
        System.out.println(bot.compute(2, 4, (a, b) -> a+b)); // 6

        System.out.println(bot.compute(2, 4, (a, b) -> a-b));

        System.out.println(bot.compute(2, 4, (a, b) -> a*b));

        System.out.println(bot.compute(2, 4, (a, b) -> a/b));

        System.out.println(bot.getShort("abc", "de", (a, b) -> a.length() - b.length()));

        System.out.println(bot.getShort("abc", "de", (a, b) -> a.charAt(0) - b.charAt(0)));

    }

    public int compute(int a, int b, BinaryOperator<Integer> binaryOperator) {
        return binaryOperator.apply(a, b);
    }

    public String getShort(String a, String b, Comparator<String> comparator) {
        return BinaryOperator.minBy(comparator).apply(a, b);
    }

}
